package com.blogsoho.taurus.dao.mapper;

import com.blogsoho.taurus.dao.builder.AttachmentSqlBuilder;
import com.blogsoho.taurus.vo.AttachmentVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by 16978 on 2017/6/17.
 */
@Mapper
public interface AttachmentMapper {

    @InsertProvider(type = AttachmentSqlBuilder.class, method = "addAttachment")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    public int addAttachment(AttachmentVo attachment);

    @SelectProvider(type = AttachmentSqlBuilder.class, method = "getAttachmentByMD5")
    @Results(id = "attachment", value = {
            @Result(property = "id", column = "id"),
            @Result(property = "title", column = "title"),
            @Result(property = "userId", column = "user_id"),
            @Result(property = "path", column = "path"),
            @Result(property = "realPath", column = "real_path"),
            @Result(property = "suffix", column = "suffix"),
            @Result(property = "md5", column = "md5"),
            @Result(property = "created", column = "created"),
            @Result(property = "contentId", column = "content_id")
    })
    public AttachmentVo getAttachmentByMD5(@Param("md5") String md5);

    @InsertProvider(type = AttachmentSqlBuilder.class, method = "addAttachmentMapping")
    public int addAttachmentMapping(@Param("aid") int aid, @Param("cid") int cid);

    @SelectProvider(type = AttachmentSqlBuilder.class, method = "getAllAttachment")
    @ResultMap("attachment")
    public List<AttachmentVo> getAllAttachment(@Param("start") int start, @Param("length") int length);

    @SelectProvider(type = AttachmentSqlBuilder.class,method = "getCount")
    public int getCount();
}
